// -*- c-basic-offset: 2 default-tab-width: 2 indent-tabs-mode: t -*-
// vim: autoindent tabstop=2 noexpandtab shiftwidth=2 softtabstop=2
//===------- RLLVMCompiler.h - The Reactor just in time compiler -----------===//
//
//                            The VMKit project
//
// This file is distributed under the Purdue University Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#ifndef _RLLVMCOMPILER_H_
#define _RLLVMCOMPILER_H_

#include "llvm/PassManager.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/LLVMContext.h"
#include "llvm/Module.h"

#include <map>

#include "vmkit/Allocator.h"
#include "RCompilerCommon.h"
#include "ReactorIntrinsics.h"

namespace llvm {
  class BasicBlock;
  class DIBuilder;
}

namespace R {
	class Reactor;
	class RModule;

  class RCompiler : public RCompilerCommon {
  		static llvm::Module* loadSelfModule();

  	protected:
		ReactorIntrinsics RIntrinsics;

  	public:
		Reactor*                   vm;
    llvm::DIBuilder*           debugFactory;  
		llvm::FunctionPassManager* pm;

    RCompiler();
    virtual ~RCompiler();

		llvm::DIBuilder* getDebugFactory() {
			return debugFactory;
		}

		ReactorIntrinsics* getIntrinsics() { return &RIntrinsics; }

		/* initialization functions */
		void            loadCommonTypes();

		llvm::Function* llvmFunction(RModule* module, uint64_t funcNo);

		void generateCode(llvm::Function* func);
  };
} // end namespace R

#endif
